<?php

abstract class ZFDulcet_Controller extends ZFKiller_Controller {
	
	protected $_isInitNavigation = true;
	protected $_typeInitDefaultCss = 'screen';
	protected $_typeInitDefaultJs = 'screen';

	public function init() {
		parent::init();
                
		if ('login' == Zend_Controller_Front::getInstance()->getRequest()->getControllerName()) {
			return;
		}

		$this->view->addHelperPath(PATH_LIB . '/Glitch/View/Helper/', 'Glitch_View_Helper');
		$this->view->addHelperPath(PATH_ZFEXTEND . '/ZFDulcet/View/Helper/', 'ZFDulcet_View_Helper');

		$this->checkLogin();
		$this->initDoctype();
		$this->initTitle();
		$this->initNavigation();
		$this->initDefaultCss();
		$this->initDefaultJs();
	}

	protected function addJQueryModal() {
		$this->view->headScript()->appendFile(HREF_STATIC_LIB . '/jq.simplemodal.js');
		$this->view->headScript()->appendFile(HREF_STATIC_LIB . '/jq.simplemodal.loading.js');

		$this->view->headLink()->prependStylesheet('/temas/mkadmin/css/modal.css', 'screen, projection, tv');
	}
        
        protected function checkLogin() {
		$auth = ZFDulcet_Auth::getInstance();
		if (!$auth->hasIdentity()) {
			$this->_redirect(ZFKiller_View_Helper_Url::urlStatic(
							array('controller' => 'login', 'action' => 'index'), null, true, false
					));
		}

		$this->view->adminUser = $auth->getIdentity();
	}
        
	protected function initDefaultCss() {
		if($this->_typeInitDefaultCss == 'screen') {
			$this->view->headLink()->appendStylesheet(ZFDULCET_LIB_DIR_CSS . '/reset.css');
			$this->view->headLink()->appendStylesheet(ZFDULCET_LIB_DIR_CSS . '/grid.css');
			$this->view->headLink()->appendStylesheet(ZFDULCET_LIB_DIR_CSS . '/config.css');
			$this->view->headLink()->appendStylesheet(ZFDULCET_LIB_DIR_CSS . '/plugin_config.css');
			$this->view->headLink()->appendStylesheet(ZFDULCET_LIB_DIR_CSS . '/ie8.css', null, 'IE8');
			$this->view->headLink()->appendStylesheet(ZFDULCET_LIB_DIR_CSS . '/mkadmin.css');
		}
		elseif($this->_typeInitDefaultCss == 'print') {
			$this->view->headLink()->appendStylesheet(ZFDULCET_LIB_DIR_CSS . '/reset-print.css', 'screen,print');
		}
	}

	protected function initDefaultJs() {
		if($this->_typeInitDefaultJs == 'screen') {
			//$this->view->headScript()->prependFile('//ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js');
            $this->view->headScript()->prependFile(ZFDULCET_LIB_DIR_PLUGINS . '/jquery-1.9.0.min.js');
		}
	}

	protected function initDoctype() {
		$this->view->getHelper('doctype')->setDoctype(Zend_View_Helper_Doctype::HTML5);
	}

	protected function initNavigation($container = null) {
		if($this->_isInitNavigation) {
			$this->view->navigation($container);
			$this->view->mainmenu($container);
			$this->view->mainmenu($container)->setUlClass('n1');
		}
	}

	protected function initTitle() {
		$this->view->headTitle('Painel de controle ' . SITE_TITLE)
				->setSeparator(' ?? ')
				->setDefaultAttachOrder(Zend_View_Helper_Placeholder_Container_Abstract::PREPEND)
		;
	}

}